package com.ryan.demo.xstream.mas.model.info;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;


public class PropInfo implements Serializable {

	private static final long serialVersionUID = -4176987968503777087L;

	/**
	 * 属性名称
	 */
	private String propName;

	/**
	 * 属性值
	 */
	private String newValue;

	/**
	 * 属性原值
	 */
	private String oldValue;

	/**
	 * 是否需要更新
	 */
	private boolean update;

	/**
	 * 是否需要校验
	 */
	private boolean needValidate = true;

	/**
	 * 元素的属性映射
	 */
	private Map<String, String> attrMap = new HashMap<String, String>();

	/**
	 * 解析属性
	 * @param nodeName
	 * @param nodeValue
	 * @return
	 */
	/*
	public static PropInfo genPropInfo(String nodeName, Object nodeValue) {
		if (StringUtils.isNotBlank(nodeName)) {
			if (!(nodeValue instanceof String)) {
				return null;
			}
			PropInfo info = new PropInfo();
			info.setPropName(nodeName);
			String value = (String) nodeValue;
			if (StringUtils.isNotBlank(value)) {
				String[] valArr = value.split(MOSConstants.SPLIT_REG);
				if (valArr == null || valArr.length == 0) {
					info.setOldValue(null);
					info.setNewValue(null);
				} else if (valArr.length == 1) {
					if (value.startsWith(MOSConstants.SPLIT_CHAR)) {
						info.setNewValue(valArr[0]);
					} else if (value.endsWith(MOSConstants.SPLIT_CHAR)) {
						info.setOldValue(valArr[0]);
					} else {
						info.setNewValue(valArr[0]);
					}
				} else if (valArr.length == 2) {
					info.setOldValue(valArr[0]);
					info.setNewValue(valArr[1]);
				} else if (valArr.length > 2) {
					throw new RuntimeException();
				}
			}
			info.setUpdate(true);
			if (StringUtils.equals(info.getOldValue(), MOSConstants.UNKNOWN_OLD_VALUE)) {
				//reset old value
				info.setOldValue(null);
				info.setNeedValidate(false);
			}
			return info;
		}
		return null;
	}
	 */
	public String getPropName() {
		return propName;
	}

	public void setPropName(String propName) {
		this.propName = propName;
	}

	public String getNewValue() {
		return newValue;
	}

	public void setNewValue(String newValue) {
		this.newValue = newValue;
	}

	public String getOldValue() {
		return oldValue;
	}

	public void setOldValue(String oldValue) {
		this.oldValue = oldValue;
	}

	/**
	 * 是否需要更新(插入或修改)
	 * @return
	 */
	public boolean isUpdate() {
		return update;
	}

	public void setUpdate(boolean update) {
		this.update = update;
	}

	public boolean isNeedValidate() {
		return needValidate;
	}

	public void setNeedValidate(boolean needValidate) {
		this.needValidate = needValidate;
	}

	public Map<String, String> getAttrMap() {
		return attrMap;
	}

	public void setAttrMap(Map<String, String> attrMap) {
		this.attrMap = attrMap;
	}

}
